package com.yuetong.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.yuetong.common.core.domain.entity.SysUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yuetong.common.annotation.Log;
import com.yuetong.common.core.controller.BaseController;
import com.yuetong.common.core.domain.AjaxResult;
import com.yuetong.common.enums.BusinessType;
import com.yuetong.business.domain.YtPlaceInfo;
import com.yuetong.business.service.IYtPlaceInfoService;
import com.yuetong.common.utils.poi.ExcelUtil;
import com.yuetong.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 场所信息，用于存储各个场所的基本信息及其层级关系Controller
 *
 * @author  卓晓君
 * @date 2025-03-07
 */
@RestController
@RequestMapping("/business/place")
public class YtPlaceInfoController extends BaseController
{
    @Autowired
    private IYtPlaceInfoService ytPlaceInfoService;

    /**
     * 查询场所信息，用于存储各个场所的基本信息及其层级关系列表
     */
    @PreAuthorize("@ss.hasPermi('business:place:list')")
    @GetMapping("/list")
    public TableDataInfo list(YtPlaceInfo ytPlaceInfo)
    {
        startPage();
        List<YtPlaceInfo> list = ytPlaceInfoService.selectYtPlaceInfoList(ytPlaceInfo);
        return getDataTable(list);
    }

    /**
     * 导出场所信息，用于存储各个场所的基本信息及其层级关系列表
     */
    @PreAuthorize("@ss.hasPermi('business:place:export')")
    @Log(title = "导出场所信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YtPlaceInfo ytPlaceInfo)
    {
        List<YtPlaceInfo> list = ytPlaceInfoService.selectYtPlaceInfoList(ytPlaceInfo);
        ExcelUtil<YtPlaceInfo> util = new ExcelUtil<YtPlaceInfo>(YtPlaceInfo.class);
        util.exportExcel(response, list, "场所信息，用于存储各个场所的基本信息及其层级关系数据");
    }


    /**
     * 获取场所信息，用于存储各个场所的基本信息及其层级关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:place:query')")
    @GetMapping(value = "/{placeId}")
    public AjaxResult getInfo(@PathVariable("placeId") Long placeId)
    {
        return success(ytPlaceInfoService.selectYtPlaceInfoByPlaceId(placeId));
    }

    /**
     * 新增场所信息，用于存储各个场所的基本信息及其层级关系
     */
    @PreAuthorize("@ss.hasPermi('business:place:add')")
    @Log(title = "新增场所信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YtPlaceInfo ytPlaceInfo)
    {
        return toAjax(ytPlaceInfoService.insertYtPlaceInfo(ytPlaceInfo));
    }

    /**
     * 修改场所信息，用于存储各个场所的基本信息及其层级关系
     */
    @PreAuthorize("@ss.hasPermi('business:place:edit')")
    @Log(title = "修改场所信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YtPlaceInfo ytPlaceInfo)
    {
        return toAjax(ytPlaceInfoService.updateYtPlaceInfo(ytPlaceInfo));
    }

    /**
     * 删除场所信息，用于存储各个场所的基本信息及其层级关系
     */
    @PreAuthorize("@ss.hasPermi('business:place:remove')")
    @Log(title = "删除场所信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{placeIds}")
    public AjaxResult remove(@PathVariable Long[] placeIds)
    {
        return toAjax(ytPlaceInfoService.deleteYtPlaceInfoByPlaceIds(placeIds));
    }

    /**
     * @Remark: * 场所信息导入模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<YtPlaceInfo> util = new ExcelUtil<YtPlaceInfo>(YtPlaceInfo.class);
        util.importTemplateExcel(response, "场所数据");
    }

    /**
     * 场所信息导入
     */
    @Log(title = "场所信息导入", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('business:place:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<YtPlaceInfo> util = new ExcelUtil<YtPlaceInfo>(YtPlaceInfo.class);
        List<YtPlaceInfo> infoList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = "";//userService.importUser(userList, updateSupport, operName);
        return success(message);
    }
}
